//
//  HYAboutUsVC.m
//  Booking
//
//  Created by Maybe_文仔 on 2018/7/28.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYAboutUsVC.h"
#import "HYTextFieldCellModel.h"
#import "HYTextFieldTableViewCell.h"
#import "HYAgreementViewController.h"

@interface HYAboutUsVC ()

/** dataSource */
@property (nonatomic,strong) HYTableViewDataSource *dataSource;
/** delegate */
@property (nonatomic,strong) HYTableViewDelegate *delegate;
/** dataSets数据源 */
@property (nonatomic,strong) NSMutableArray *dataSetsArray;
@property (nonatomic,strong) NSMutableArray *sectionArray;
@property (nonatomic,strong) UITableView *tableView;

@property (weak, nonatomic) IBOutlet UILabel *appVersionLab;

@end

@implementation HYAboutUsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = NSLocalizedString(@"about", nil);
    [self setupSubviews];
    [self setupData];
    [self bindingTableViewCell];
    // Do any additional setup after loading the view from its nib.
}

-(void)setupSubviews{
    self.appVersionLab.text = [NSString stringWithFormat:@"M Booking %@",[self appVersion]];
    
    self.dataSource.dataSource = self.dataSetsArray;
    self.delegate.dataSource = self.dataSetsArray;
    [self.view addSubview:self.tableView];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.appVersionLab.mas_bottom).offset(13);
    }];
}

- (void)setupData{
    
    NSMutableArray *sectionArray = [NSMutableArray array];
 
    NSArray *titlesArray = @[NSLocalizedString(@"hotline", nil),
                             NSLocalizedString(@"termsOfUse", nil)];
    NSArray *valuesArray = @[@"82738232",@""];
    for (NSInteger i = 0; i < titlesArray.count; i++) {
        
        HYTextFieldCellModel *textFieldCellModel = [HYTextFieldCellModel new];
        textFieldCellModel.cellIdientifier = @"HYTextFieldTableViewCell";
        textFieldCellModel.cellHeight = 50;
        textFieldCellModel.title = titlesArray[i];
        textFieldCellModel.value = valuesArray[i];
        textFieldCellModel.indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        textFieldCellModel.inputMode = (i == 0 ? HYTextFieldCellInputModeNotEdit: HYTextFieldCellInputModeSelect);
        [sectionArray addObject:textFieldCellModel];
    }
    
    [self.dataSetsArray addObject:sectionArray];
    [self.tableView reloadData];
}

- (void)bindingTableViewCell{
    kWeakSelf(weakSelf);
    [self.delegate setDidSelectedBlock:^(UITableView *tableView, NSIndexPath *indexPath) {
        if (indexPath.row == 1) {
            HYAgreementViewController *agreementViewController = [HYAgreementViewController new];
            
            [weakSelf presentViewController:agreementViewController animated:YES completion:nil];
        }
    }];
}

//获取版本号
-(NSString *)appVersion{
    
    return [NSString stringWithFormat:@"%@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
}

#pragma mark -- Lazyload

-(HYTableViewDelegate *)delegate{
    if (!_delegate) {
        _delegate = [HYTableViewDelegate new];
    }
    return _delegate;
}

-(HYTableViewDataSource *)dataSource{
    if (!_dataSource) {
        _dataSource = [HYTableViewDataSource new];
    }
    return _dataSource;
}

-(NSMutableArray *)dataSetsArray{
    if (!_dataSetsArray) {
        _dataSetsArray = [NSMutableArray new];
    }
    return _dataSetsArray;
}

- (UITableView *)tableView{
    
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.backgroundColor = KAPP_Clear_COLOR;
        _tableView.bounces = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self.delegate;
        _tableView.dataSource = self.dataSource;
        _tableView.emptyDataSetSource = self;
        _tableView.emptyDataSetDelegate = self;
        [_tableView registerClass:[HYTextFieldTableViewCell class] forCellReuseIdentifier:@"HYTextFieldTableViewCell"];
    }
    return _tableView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
